//
//  ZCLoginViewController.m
//  BaiSi
//
//  Created by 张灿 on 16/4/28.
//  Copyright © 2016年 张灿. All rights reserved.
//

#import "ZCLoginViewController.h"
#import "ZCLogView.h"
#import "ZCFastLoginView.h"

@interface ZCLoginViewController ()
@property (weak, nonatomic) IBOutlet UIView *loginView;
//中间登录界面左侧距离屏幕边缘的约束
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leadCons;
//中间登录界面的宽
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *loginW;
@property (weak, nonatomic) IBOutlet UIView *bottomV;

@end

@implementation ZCLoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    //加载中间的登录界面
    [self setupLoginView];
    //设置中间登录按钮的宽等于两倍的屏幕宽
    self.loginW.constant = ZCScreenW * 2;
    
    //加载底部快速登录
    ZCFastLoginView *fastV = [ZCFastLoginView fastView];
    [self.bottomV addSubview:fastV];
}

//加载中间的登录界面
- (void)setupLoginView
{
    //加载登录界面
    ZCLogView *loginV = [ZCLogView loginView];
    [self.loginView addSubview:loginV];
    
    //加载注册界面
    ZCLogView *registerV = [ZCLogView registerView];
    [self.loginView addSubview:registerV];
}

//设置子控件(中间登录界面)frame
- (void)viewDidLayoutSubviews
{
    //中间登录界面frame
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = self.loginView.frame.size.width * 0.5;
    CGFloat h = self.loginView.frame.size.height;
    self.loginView.subviews[0].frame = CGRectMake(x, y, w, h);
    self.loginView.subviews[1].frame = CGRectMake(w, y, w, h);
    
    //底部快速登录frame
    self.bottomV.subviews[0].frame = CGRectMake(0, 0, self.bottomV.bounds.size.width, self.bottomV.bounds.size.height);
}

//点击注册按钮
- (IBAction)registClick:(UIButton *)sender {
    sender.selected = !sender.selected;
    self.leadCons.constant = self.leadCons.constant == 0 ? -ZCScreenW : 0;
    [UIView animateWithDuration:0.25 animations:^{
        [self.view layoutIfNeeded];
    }];
}


//关闭注册界面
- (IBAction)closeClick:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

//触摸屏幕关闭键盘
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

/**
 *  设置状态栏显示
 */
-(UIStatusBarStyle)preferredStatusBarStyle{
    
    return UIStatusBarStyleLightContent;
}



@end
